<?php
namespace app\article\model;
use think\Db;
use think\Controller;

class ArticlesCategoryTpl extends Controller
{
    public function getCategoryByTag($tag)
    {
        $tag = json_decode($tag,true);
        $whereArray = [];
        foreach ($tag as $key => $val) {
            if (strpos($key, 'where') !== false) {
               	if (strpos($val, '=') !== false) {
                    $tempVal = explode('=', $val);
                    $whereArray[trim($tempVal[0])] = trim($tempVal[1]);
                }
                if (strpos($val, '<>') !== false) {
                    $tempVal = explode('<>', $val);
                    $whereArray[trim($tempVal[0])] = ['<>',trim($tempVal[1])];
                    break;
                }
                if (strpos($val, 'like') !== false) {
                    $tempVal = explode('like', $val);
                    $whereArray[trim($tempVal[0])] = ['like',trim($tempVal[1])];
                }
                if (strpos($val, '>') !== false) {
                    $tempVal = explode('>', $val);
                    $whereArray[trim($tempVal[0])] = ['>',trim($tempVal[1])];
                }
                if (strpos($val, '<') !== false) {
                    $tempVal = explode('<', $val);
                    $whereArray[trim($tempVal[0])] = ['<',trim($tempVal[1])];
                }
            }
        }
        
        $tag['whereArray'] = $whereArray;
        return model('app\tag\model\TagsCategory')->getCategory($tag);
    }
    
}